<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div>
    <div fxFlex="70">
      <div fxLayout="row" fxLayoutAlign="center">
        <div fxFlex>
          <span *ngIf="isEmpty">There are no</span><b *ngIf="!isEmpty">{{userRoles.length}}</b> role(s) assigned to this user.
        </div>
        <div style="height: 40px;">
          <button *ngIf="editMode" color="primary" mat-stroked-button (click)="add()">Assign roles</button>
        </div>
      </div>
      <mat-divider *ngIf="isEmpty" style="margin-bottom: 20px;"></mat-divider>
      <ngx-datatable *ngIf="!isEmpty" class="material"
                     [columnMode]="'flex'"
                     [headerHeight]="40"
                     [footerHeight]="40"
                     [rowHeight]="50"
                     [rows]='userRoles'>
        <ngx-datatable-column name="Name" [flexGrow]="2">
          <ng-template let-row="row" ngx-datatable-cell-template>
            {{row.name}}
          </ng-template>
        </ngx-datatable-column>
        <ngx-datatable-column name="Description" [flexGrow]="4">
          <ng-template let-row="row" ngx-datatable-cell-template>
            {{row.description}}
          </ng-template>
        </ngx-datatable-column>
        <ngx-datatable-column [flexGrow]="1">
          <ng-template let-row="row" ngx-datatable-cell-template>
            <div fxLayout="row" class="gv-table-cell-actions" *ngIf="editMode">
              <button mat-icon-button (click)="revoke($event, row)"><mat-icon matTooltip="Revoke role">highlight_off</mat-icon></button>
            </div>
          </ng-template>
        </ngx-datatable-column>
      </ngx-datatable>

      <app-emptystate *ngIf="isEmpty"
                      [message]="'No roles assigned'"
                      [subMessage]="'No data to display'"
                      [icon]="'perm_contact_calendar'"></app-emptystate>

    </div>
    <div class="gv-page-description" fxFlex>
      <h3>User roles</h3>
      <div class="gv-page-description-content">
        <p>
          Roles allow users to sign in and access any protected resources that match roles' permissions requirements.
        </p>
      </div>
    </div>
</div>

